package com.second.app.controller;

import com.second.app.annoation.JwtToken;
import com.second.app.common.SecondResponse;
import com.second.app.enums.CommonCodeEnum;
import com.second.app.thread.stream.io.FileReadWriteExample;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author gyz
 * @date 2020/12/26 9:33
 */
@RestController
@RequestMapping("/second")
public class TestController {

    @GetMapping("/device/create")
    @JwtToken
    public SecondResponse create(@ApiParam(value = "令牌", required = true) @RequestHeader("token") String token) {

        System.out.println("token:::::" + token);
        return SecondResponse.success(CommonCodeEnum.OK.getCode(), "设备创建成功");
    }

    @GetMapping("/device/downLoadFileToExplorer")
    @JwtToken
    public SecondResponse downLoadFileToExplorer(HttpServletRequest request, HttpServletResponse response) {
        try {
            FileReadWriteExample.downLoadFileToExplorer(request, response);
            return SecondResponse.success(CommonCodeEnum.OK.getCode(), "文件下载成功");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
